<?php
class SystemSettingAction extends Action{
    
    public function main(){
        $this->_request['action'] = isset($this->_request['action']) ? $this->_request['action'] : 'default';
        switch ($this->_request['action']) {
            case 'modify':
                $this->__modify();
                break;
            default:
                $this->__load();
                break;
        }

    }

    private function __load(){
        $row = array();
        $obj = new  SystemSettingDAO();
        $row =$obj->getOneByID(1); 
        if ($row){
            foreach ($row as $key => $value) {
                $this->_response[$key] = $value;
            }
        }
        //debug($row);
    }


    private function __modify(){
        $inputarr =  array();
        $inputarr['CopyRight'] = $this->_request['CopyRight'];
        $filepath = FILE_UPLOAD_PATH.SLASH.'Logo';
        $fileupload = new Fileupload($filepath);
        if ($_FILES["Logo"]['tmp_name']) {
            $fileupload->run("Logo",1);
            $inputarr['Logo'] = $filepath.SLASH.$fileupload->saveName;
        }
        $obj = new  SystemSettingDAO();
        $row =$obj->getOneByID(1);
        if ($row){
            $ret = $obj->modify(1,$inputarr);
        }else {
            $ret = $obj->add($inputarr);
        }

        header("Location:index.php?do=index/system_setting");

    }




}